package org.huawei260.TiKu.ODsuanfa;

import java.util.Arrays;
import java.util.Arrays;
import java.util.Scanner;
/**
 * @Author: qingle
 * @Date: 2024/10/28-16:11
 * @Description: 2556 【排序】2024D开源项目热榜
 * @version: 1.0
 */
public class D_2024D_2556__排序开源项目热榜 {

//	public class Main {
		static class Project {
			String name;
			int hot;

			public Project(String name, int hot) {
				this.name = name;
				this.hot = hot;
			}
		}

		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);

			int n = sc.nextInt();

			int[] weights = new int[5];
			for (int i = 0; i < 5; i++) {
				weights[i] = sc.nextInt();
			}

			Project[] projects = new Project[n];

			for (int i = 0; i < n; i++) {
				String name = sc.next();

				int hot = 0;
				for (int j = 0; j < 5; j++) {
					hot += sc.nextInt() * weights[j];
				}

				projects[i] = new Project(name, hot);
			}

			Arrays.sort(
				projects,
				(a, b) ->
					a.hot != b.hot ? b.hot - a.hot : a.name.toLowerCase().compareTo(b.name.toLowerCase()));

			for (Project project : projects) {
				System.out.println(project.name);
			}
		}
	}